﻿using Basic.UserModel.User;
using Basic.UserRepository;
using WeDonekRpc.Client;
using WeDonekRpc.Client.Ioc;
using WeDonekRpc.Helper;
using WeDonekRpc.Helper.Interface;

namespace Basic.UserCollect.Extend
{
    internal static class RefreshLastLoginDate
    {
        private static readonly IDelayDataSave<long> _SaveLog = new DelayDataSave<long>(_Save, 1000, 20);

        private static void _Save ( ref long[] datas )
        {
            using ( IocScope scope = RpcClient.Ioc.CreateScore() )
            {
                IUserRepository repository = scope.Resolve<IUserRepository>();
                repository.SetLastLoginDate(datas);
            }
        }

        public static void Refresh ( UserDatum user )
        {
            if ( user.LastLoginDate != HeartbeatTimeHelper.CurrentDate )
            {
                _SaveLog.AddData(user.Id);
            }
        }
    }
}
